<html>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <script src="../commonCss.js"></script>
    <script src="../commonJs.js"></script>
    <link rel="stylesheet" href="../../css/common.css">
</head>

<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <div class="ctc_title">用户管理</div>
    <div class="down_line"></div>
</section>

<!-- Main content -->
<section class="content" >
    <div class="row">
        <div class="col-xs-12">
            <div class="box-header">
                <form class="form-inline">
                    <label>查询:</label>
                    <div class="form-group">
                        <select class="form-control" id="searchType">
                            <option value="">全部</option>
                            <option value="1">PLUS会员</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <input style="width: 260px;" class="form-control" type="text" id="searchKey"  placeholder="输入账号/手机号/昵称/真实姓名搜索"/>
                    </div>
                    <div class="form-group">
                        <button type="button"  onclick="getData()"  class="btn btn-block btn-primary">搜索</button>
                    </div>

                </form>
            </div>

            <div class="box-body" style="height:100%;">
                <table id="dataList" class="table table-bordered table-hover" >
                    <thead>
                    <tr>
                        <th>用户ID</th>
                        <th>用户账号</th>
                        <th>用户昵称</th>
                        <th>手机号</th>
                        <th>真实姓名</th>
                        <th>会员</th>
                        <th>总积分</th>
                        <th>总信用分</th>
                        <th>银行卡数量</th>
                        <th>是否实名</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody >
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>

<!-- 【查看银行卡详情】弹出窗内容 -->
<div class="modal" id="cardDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static" >
    <div class="modal-dialog">
        <div class="modal-content" style="width: 180%;height: 75%;margin-left: -40%;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" align="center">用户信用卡列表</h4>
            </div>
                <div class="box-body" style="height:100%;">
                    <table id="cardList" class="table table-bcardordered table-hover" >
                        <thead>
                        <tr>
                            <th>卡号</th>
                            <th>银行名</th>
                            <th>类型</th>
                            <th>邮箱账号</th>
                            <th>邮箱密码</th>
                            <th>邮箱独立密码</th>
                            <th>卡状态</th>
                            <th>创建时间</th>
                        </tr>
                        </thead>
                        <tbody >
                        </tbody>
                    </table>
                </div>
        </div>
    </div>
</div>

<!-- 【删除】弹出窗内容 -->
<div class="modal" id="deleteDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" align="center">提示</h4>
            </div>
            <div class="modal-body">
                <h4 align="center">确定删除？</h4>
                <h5 align="center" style="color: gray;">删除后不可恢复</h5>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-primary"  onclick="comfirmeDel();">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- page script -->
<script>
    $(document).ready(function() {
        layui.use('layer', function(){
            var layer = layui.layer;
        });
        //加载数据
        getData();
    });

    // 加载数据
    function getData(){
        var table = $('#dataList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,    //true代表后台处理分页，false代表前台处理分页
            "ajax" :  {
                url:"/user/getUserList",
                type:"post",
                data:{
                    key : $("#searchKey").val(),
                    type : $("#searchType").val()
                },
                dataSrc: function (myJson) {
                    return myJson.data.data;
                }
            },
            //参数显示
            "columns": [
                {"data": "id", 'sClass': "text-center",'width': '5%'},
                {"data": "account", 'sClass': "text-center",'width': '10%'},
                {"data": "username", 'sClass': "text-center",'width': '5%'},
                {"data": "mobile", 'sClass': "text-center",'width': '8%'},
                {"data": "partyName", 'sClass': "text-center",'width': '8%'},
                {"data": "isPlus", 'sClass': "text-center","width":'5%',
                    "render":function(data,type,full,meta){
                        var str="";
                        if(data == 1){
                            str += "<span class='label label-default' style='background-color:#FFFFFF00!important;'>" + toDate(full.plusExpireTime).format('yyyy-MM-dd') + " 到期" + "</span>";
                        } else {
                            if (full.plusExpireTime != null) {
                                str += "<span class='label label-default'>" + toDate(full.plusExpireTime).format('yyyy-MM-dd') + " 已到期" + "</span>";
                            }
                        }
                        return str;
                    }
                },
                {"data": "userPoint", 'sClass': "text-center",'width': '5%'},
                {"data": "creditPoint", 'sClass': "text-center",'width': '5%'},
                {"data": "cardTotal", 'sClass': "text-center",'width': '6%',
                    "render": function (data, type, full, meta ) {
                        var str = "<a href = '#' title='查看银行卡详情' onclick=getCardDetail(" + full.id +");>" +data+ "</a>";
                        return str;
                    }
                },
                {"data": "value", 'sClass': "text-center","width":'5%',
                    "render":function(data,type,full,meta){
                        var str="";
                        if(data >= 60 || full.autheType == 1 || full.autheType == 2){
                            if (full.autheType == 2) {
                                str += "<span class='label label-warning' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>(银行卡验证)</span>";
                                str += "<br>";
                            } else if (full.autheType == 1) {
                                str += "<span class='label label-warning' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>(身份证读取)</span>";
                                str += "<br>";
                            }
                            str += "<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>是</span>";
                        } else{
                            str += "<span class='label label-danger' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>否</span>";
                        }
                        return str;
                    }
                },
                {"data": "createTime", 'sClass': "text-center",'width': '8%',
                    "render":function( data, type, full, meta) {
                        return toDate(data).format('yyyy-MM-dd HH:mm:ss');
                    }
                },
                {"data":"id" , 'sClass': "text-center" ,'width':'5%',
                    "render": function (data, type, full, meta ) {
                        var str = "<a href = '#' title='查看详情' onclick=editData(" + data +","+full.userPoint+","+full.creditPoint+");><i class='\glyphicon glyphicon-eye-open'></i></a>&nbsp;&nbsp;&nbsp;";
                        // str = str + "<a href = '#' title='删除' onclick = deleteData(" + data +");><i class='glyphicon glyphicon-trash'></i></a>";
                        return str;
                    }
                }
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
    }

    //删除用户弹框确认页面
    var messageId = 0;
    function deleteData(id){
        messageId = id;
        $("#deleteDialog").modal("show");
    }

    //删除用户
    function  comfirmeDel(){
        $.ajax({
            type:"POST",
            url:"/user/deleteUser",
            async : true,//默认就是true
            dataType:"json",
            data:{
                "id" : messageId
            },
            success:function(data){
                if(!data.error){
                    layer.msg(data.message);
                    getData();
                }else{
                    layer.msg(data.message);
                }
            },
            failure:function(data) {
                alert('网络错误！');
            },
        });
    }

    //查看用户详情
    function editData(id,userPoint,userCredit) {
        window.location.href="userDetail.html?userId="+id+"&userPoint="+userPoint+"&userCredit="+userCredit;
    }

    //查看银行卡详情
    function getCardDetail(userId) {
        var table = $('#cardList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,    //true代表后台处理分页，false代表前台处理分页
            "ajax" :  {
                url:"/card/getCardByUserId",
                type:"post",
                data:{
                    userId : userId,
                    cardKey : $("#cardKey").val()
                },
                dataSrc: function (myJson) {
                    return myJson.data.data;
                }
            },
            //参数显示
            "columns": [
                {"data": "cardNum", 'sClass': "text-center",'width': '13%'},
                {"data": "bankName", 'sClass': "text-center",'width': '12%'},
                {"data": "type", 'sClass': "text-center",'width': '7%',
                    "render":function( data, type, full, meta) {
                        var str = "";
                        if(data == 0){
                            str += "信用卡";
                        }else if (data == 1) {
                            str += "储蓄卡";
                        }else {
                            str += "支付宝";
                        }
                        return str;
                    }
                },
                {"data": "email", 'sClass': "text-center",'width': '10%'},
                {"data": "emailPwd", 'sClass': "text-center",'width': '10%'},
                {"data": "emailPwdSelf", 'sClass': "text-center",'width': '10%'},
                {"data": "status", 'sClass': "text-center",'width': '5%',
                    "render":function( data, type, full, meta) {
                        var str = "";
                        if(data == 0){
                            str += "<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >未授权</span> ";
                        }else if(data == 1){
                            str += "<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >授权成功</span> ";
                        }else{
                            str += "<span class='label label-danger' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>授权失败</span>";
                        }
                        return str;
                    }
                },
                {"data": "createTime", 'sClass': "text-center",'width': '13%',
                    "render":function( data, type, full, meta) {
                        return toDate(data).format('yyyy-MM-dd HH:mm:ss');
                    }
                }
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
        $("#cardDialog").modal("show");
    }
</script>
</body>
</html>
